package com.gupao.micro.services.reactive.webflux;

import org.springframework.expression.Operation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.validation.Valid;
import java.net.URISyntaxException;

@RestController
public class WebFluxController {

    @RequestMapping("")
    public Mono<String> index() {
        // 执行计算
        println("执行计算");
        Mono<String> result =  Mono.fromSupplier(() -> {

            println("返回结果");

            return "Hello,World";
        });

        return result;
    }

    private static void println(String message) {
        System.out.printf("[线程 : %s] %s\n",
                Thread.currentThread().getName(), // 当前线程名称
                message);
    }
//    @PutMapping("/operations")
//    public Mono<Operation> updateOperation(@Valid @RequestBody Operation operation)
//            throws URISyntaxException {
//
//        return operationRepository.save(operation);
//    }
//@Repository
//public interface BankAccountRepository extends ReactiveMongoRepository<BankAccount,String> {
//    Mono<BankAccount> getFirstByBalanceEndingWith(BigDecimal bigDecimal);
//    Mono<Long> countByBalanceEquals(BigDecimal bigDecimal);
//    Flux<BankAccount> findAllByIdBefore(UUID uuid);
//}
}
